let Peer = require('./peer.js')
//大脑
module.exports = class Brain{
    constructor(){
        //100个神经节
        this.main = new Peer('main')
        this.peers = []
        this.count = 0
    }
    input(key, value = ''){
        key = key.toString()
        let found = this.__find(key)
        this.main.add(key)
        return found.addAndGet(value)
        // let next = this.main.get(key)
        // if(next.length > 0) console.log(`${key}: ${JSON.stringify(next)}`)
    }
    output(){

    }
    feedBack(key, value = '', score = 0.8){
        key = key.toString()
        value = value.toString()
        let found = this.__find(key)
        found.set(score, key, value)
    }
    __find(key){
        let found = false
        for(let index in this.peers){
            if(this.peers[index].key == key) found = index
        }
        if(!found){
            this.peers.push(new Peer(key))
            this.count ++
            return this.__find(key)
        }
        return this.peers[found]
    }
}